<!doctype html>
<html lang="en">
<head>
    <title>Code coverage report for utils/scroll-to.ts</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="../prettify.css" />
    <link rel="stylesheet" href="../base.css" />
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <style type='text/css'>
        .coverage-summary .sorter {
            background-image: url(../sort-arrow-sprite.png);
        }
    </style>
</head>
<body>
<div class='wrapper'>
  <div class='pad1'>
    <h1>
      <a href="../index.html">All files</a> / <a href="index.html">utils</a> scroll-to.ts
    </h1>
    <div class='clearfix'>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Statements</span>
        <span class='fraction'>0/30</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Branches</span>
        <span class='fraction'>0/17</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Functions</span>
        <span class='fraction'>0/7</span>
      </div>
      <div class='fl pad1y space-right2'>
        <span class="strong">0% </span>
        <span class="quiet">Lines</span>
        <span class='fraction'>0/29</span>
      </div>
    </div>
  </div>
  <div class='status-line low'></div>
<pre><table class="coverage">
<tr><td class="line-count quiet">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51</td><td class="line-coverage quiet"><span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-no">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">const easeInOutQuad = <span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >(t</span>: number, b: number, c: number, d: number) =&gt; {</span>
<span class="cstat-no" title="statement not covered" >  t /= d / 2</span>
<span class="cstat-no" title="statement not covered" >  if (t &lt; 1) {</span>
<span class="cstat-no" title="statement not covered" >    return c / 2 * t * t + b</span>
  }
<span class="cstat-no" title="statement not covered" >  t-</span>-
<span class="cstat-no" title="statement not covered" >  return -c / 2 * (t * (t - 2) - 1) + b</span>
}
&nbsp;
// requestAnimationFrame for Smart Animating http://goo.gl/sx5sts
const requestAnimFrame = (<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >function() {</span></span>
<span class="cstat-no" title="statement not covered" >  return window.requestAnimationFrame || window.webkitRequestAnimationFrame || (window as any).mozRequestAnimationFrame || <span class="fstat-no" title="function not covered" >function(</span>callback) { <span class="cstat-no" title="statement not covered" >window.setTimeout(callback, 1000 / 60) }</span></span>
})()
&nbsp;
// Because it's so fucking difficult to detect the scrolling element, just move them all
const move = (<span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >amount: number) =&gt; {</span></span>
<span class="cstat-no" title="statement not covered" >  document.documentElement.scrollTop = amount;</span>
  (<span class="cstat-no" title="statement not covered" >document.body.parentNode as HTMLElement).scrollTop = amount</span>
<span class="cstat-no" title="statement not covered" >  document.body.scrollTop = amount</span>
}
&nbsp;
const position = <span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >() =&gt;</span> {</span>
<span class="cstat-no" title="statement not covered" >  return document.documentElement.scrollTop || (document.body.parentNode as HTMLElement).scrollTop || document.body.scrollTop</span>
}
&nbsp;
export const scrollTo = <span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >(t</span>o: number, duration: number, callback?: Function) =&gt; {</span>
  const start = <span class="cstat-no" title="statement not covered" >position()</span>
  const change = <span class="cstat-no" title="statement not covered" >to - start</span>
  const increment = <span class="cstat-no" title="statement not covered" >20</span>
  let currentTime = <span class="cstat-no" title="statement not covered" >0</span>
<span class="cstat-no" title="statement not covered" >  duration = (typeof (duration) === 'undefined') ? 500 : duration</span>
  const animateScroll = <span class="cstat-no" title="statement not covered" ><span class="fstat-no" title="function not covered" >function() {</span></span>
    // increment the time
<span class="cstat-no" title="statement not covered" >    currentTime += increment</span>
    // find the value with the quadratic in-out easing function
    const val = <span class="cstat-no" title="statement not covered" >easeInOutQuad(currentTime, start, change, duration)</span>
    // move the document.body
<span class="cstat-no" title="statement not covered" >    move(val)</span>
    // do the animation unless its over
<span class="cstat-no" title="statement not covered" >    if (currentTime &lt; duration) {</span>
<span class="cstat-no" title="statement not covered" >      requestAnimFrame(animateScroll)</span>
    } else {
<span class="cstat-no" title="statement not covered" >      if (callback &amp;&amp; typeof (callback) === 'function') {</span>
        // the animation is done so lets callback
<span class="cstat-no" title="statement not covered" >        callback(</span>)
      }
    }
  }
<span class="cstat-no" title="statement not covered" >  animateScroll(</span>)
}
&nbsp;</pre></td></tr>
</table></pre>
<div class='push'></div><!-- for sticky footer -->
</div><!-- /wrapper -->
<div class='footer quiet pad2 space-top1 center small'>
  Code coverage
  generated by <a href="https://istanbul.js.org/" target="_blank">istanbul</a> at Mon Aug 05 2019 17:01:25 GMT+0800 (GMT+08:00)
</div>
</div>
<script src="../prettify.js"></script>
<script>
window.onload = function () {
        if (typeof prettyPrint === 'function') {
            prettyPrint();
        }
};
</script>
<script src="../sorter.js"></script>
</body>
</html>
